fix(webtransport): prevent Chrome DNS port-scanning penalty#3357
fix(webtransport): prevent Chrome DNS port-scanning penalty#3357aannaannyaaa wants to merge 1 commit intolibp2p:mainfrom
Conversation
|
Hi @aannaannyaaa ! There are a few issues I've spotted. The first has to do with simple linting issues like trailing spaces and unused variables. The second issue is more structural. I don't see where the dns address in the ma is actually being turned into an ip before its handed to the WebTransport construction which would be doing the dns resolution. From reading the original issue I believe the implied action was to use the dns service from libp2p or a new instance of From a glance it looks like the best place to put that logic would be directly before the WebTransport construction. The isChrome method you've added looks good. |
Fix Chrome WebTransport DNS port-scanning penalty
Fixes #3286
Problem
Chrome has an anti-port-scanning mechanism that penalizes cancelled WebTransport requests. When a DNS-based multiaddr is dialed and cancelled before DNS resolution completes, Chrome stores the penalty against an empty string key instead of a specific IP address.
This causes ALL future DNS-based WebTransport dials to be penalized, not just dials to that specific host.
Solution
This PR adds DNS pre-resolution for WebTransport multiaddrs in Chrome only:
isChrome())hasDNSComponent())Key Changes
isChrome()function to detect Chrome/Chromium browsershasDNSComponent()to detect DNS-based multiaddrsresolveMultiaddrDNS()to create async boundary for Chromedial()to pre-resolve DNS before dialingdialSingleAddress()private method for cleaner separationHow It Works
The async boundary (
await setTimeout(0)) ensures we yield to the event loop, giving Chrome's internal DNS resolver time to complete before the WebTransport session is created:Test Results
✅ 22/22 tests passing in browser environment
✅ 22/22 tests passing in webworker environment
✅ All new Chrome DNS tests passing (11 new tests)
✅ No regressions in existing tests
New Tests Added
Browser Compatibility
Breaking Changes
None. This is a backward-compatible fix that only affects Chrome browsers with DNS-based multiaddrs.